package demo;

import domain.Book;

import java.util.Arrays;

public class Demo6 {
    public static void main(String[] args) {
        Book[] arr = new Book[5];
        arr[0] = new Book(001, "Java入门", "张三", 100, 200, 300);
        arr[1] = new Book(002, "Java熟悉", "李四", 100, 100, 300);
        arr[2] = new Book(003, "Java精通", "王二麻子", 100, 400, 300);
        arr[3] = new Book(004, "Java掉发", "钱六", 100, 300, 300);
        arr[4] = new Book(005, "Java大神", "赵七", 100, 500, 300);
        System.out.println("排序前：");
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i].getSales() + "\t");
        }



    outer:    for (int i = 0; i < arr.length-1; i++) {

            boolean flag = true;
       inner:     for (int j = 0; j<arr.length-1-i;j++) {
           if (arr[j].getSales() < arr[j + 1].getSales()) {
               flag = false;
               Book temp = arr[j];
               arr[j] = arr[j + 1];
               arr[j + 1] = temp;
           }
       }
                if (flag) {
                    break outer;
                }
            }

        System.out.println();
        System.out.println("排序后：");
        for(int i = 0; i < arr.length; i++) {
            System.out.print(arr[i].getSales() + "\t");
        }

    }
}
